package com.zhuimeng.controller;

import com.zhuimeng.pojo.Resume;
import com.zhuimeng.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class ResumeController {
    @Autowired
    ResumeService service;

    @RequestMapping(value = "resume",method = RequestMethod.GET)
    public Map<String, Object> findAll(Integer pageNum, Integer pageSize){
        Page<Resume> resumes = service.findAll(pageNum, pageSize);

        Map<String, Object> map = new HashMap<>();
        map.put("length", resumes.getTotalElements());
        map.put("iTotalRecords", 10);
        map.put("iTotalDisplayRecords", 1);
        map.put("start", 0);
        map.put("recordsTotal", 10);
        map.put("recordsFiltered", 3);
        map.put("data", resumes.getContent());


        return map;
    }

    @RequestMapping(value = "/resume/{id}",method = RequestMethod.GET)
    public Resume findById(@PathVariable Long id){
        return service.findById(id);
    }

    @RequestMapping(value = "resume",method = RequestMethod.POST)
    public Resume save(Resume resume){
        return service.save(resume);
    }

    @RequestMapping(value = "resume/{id}",method = RequestMethod.DELETE)
    public void deleteById(@PathVariable Long id){
        service.deleteById(id);
    }
}
